﻿@page "/products"
@attribute [Authorize]
@using ClassifiedAds.Blazor.Modules.Products.Components

<div class="card">
	<div class="card-header">
		Search
	</div>
	<div class="card-body">
		<div class="input-group">
			<InputText @bind-Value="SearchText" class="form-control" placeholder="Search by Description" />
			<button type="button" class="btn btn-primary" style="margin-left:10px;" @onclick="VectorSearch">
				Vector Search
			</button>
			<button type="button" class="btn btn-secondary" style="margin-left:10px;" @onclick="ClearSearch">
				Clear
			</button>
		</div>
	</div>
</div>

<div class="card">
	<div class="card-header">
		Product List

		<div style="float: right">
			<button type="button" class="btn btn-secondary" @onclick="ExportAsPdf">
				Export as Pdf
			</button>
			&nbsp;
			<button type="button" class="btn btn-secondary" @onclick="ExportAsCsv">
				Export as Csv
			</button>
			&nbsp;
			<button class="btn btn-primary"
					style="float: right;"
					@onclick="QuickAddProduct">
				Add Product
			</button>
		</div>
	</div>
	<div class="card-body">
		<div class="table-responsive">

			@if (Products == null)
			{
				<p><em>Loading...</em></p>
			}
			else
			{
				<table class="table">
					<thead>
						<tr>
							<th>Name</th>
							<th>Code</th>
							<th>Description</th>
							@if (ShowSimilarityScore)
							{
								<th>Similarity Score</th>
							}
							<th></th>
						</tr>
					</thead>
					<tbody>
						@foreach (var product in Products)
						{
							<tr @key="product.Id">
								<td><a href="@($"/products/{product.Id}")">@product.Name</a></td>
								<td>@product.Code</td>
								<td>@product.Description</td>
								@if (ShowSimilarityScore)
								{
									<td>@product.SimilarityScore</td>
								}
								<td>
									<button @onclick="(() => EditProduct(product))" class="btn btn-primary" title="Edit">Edit</button>
									<button @onclick="(() => ViewAuditLogs(product))" class="btn btn-secondary" title="View Audit Logs">View Audit Logs</button>
									<button @onclick="(() => DeleteProduct(product))" class="btn btn-danger" title="Delete">Delete</button>
								</td>
							</tr>
						}
					</tbody>
				</table>
			}
		</div>
	</div>
</div>

<AuditLogsDialog @ref="AuditLogsDialog"></AuditLogsDialog>
<ConfirmDialog @ref="DeleteDialog" Title="Delete Product" YesText="Yes" NoText="No" ConfirmEventCallback="ConfirmedDeleteProduct">
	<Message>
		Are you sure you want to delete product: <strong>@DeletingProduct.Name</strong>
	</Message>
</ConfirmDialog>
